#include <string>
#include "atomic.h"
#include "message.h"
#include "mainsimu.h"
#include "strutil.h"
#include "../HeadFile/ERP_mixing_7_model.h"


/**** the Constructor ****/
ERP_mixing_7_model::ERP_mixing_7_model( const string &name)
: Atomic( name )
, ERP_mixing_7_stream_DO_1( this->addInputPort( "ERP_mixing_7_stream_DO_1") )
, ERP_mixing_7_stream_DO_3( this->addInputPort( "ERP_mixing_7_stream_DO_3") )
, ERP_mixing_7_stream_DO_2( this->addInputPort( "ERP_mixing_7_stream_DO_2") )
, ERP_mixing_7_stream_DO_4( this->addOutputPort( "ERP_mixing_7_stream_DO_4") )
{

}


/*** the initFunction ***/
Model &ERP_mixing_7_model::initFunction()
{

		
	ERP_mixing_7_stream_DO_4_flowrate = 0;
	count = 0;
	count = 0;
	delay = "00:00:00:00";
	passivate();
	return *this;
		
		
}

/*** the externalFunction ***/
Model &ERP_mixing_7_model::externalFunction( const ExternalMessage &msg )
{

			
	if( msg.port() == ERP_mixing_7_stream_DO_1 ){
		ERP_mixing_7_stream_DO_1_flowrate = msg.value();
		ERP_mixing_7_stream_DO_4_flowrate += ERP_mixing_7_stream_DO_1_flowrate;
		count++;
		holdIn( active, delay);
		return *this;
	}
	if( msg.port() == ERP_mixing_7_stream_DO_2 ){
		ERP_mixing_7_stream_DO_2_flowrate = msg.value();
		ERP_mixing_7_stream_DO_4_flowrate += ERP_mixing_7_stream_DO_2_flowrate;
		count++;
		holdIn( active, delay);
		return *this;
	}
	if( msg.port() == ERP_mixing_7_stream_DO_3 ){
		ERP_mixing_7_stream_DO_3_flowrate = msg.value();
		ERP_mixing_7_stream_DO_4_flowrate += ERP_mixing_7_stream_DO_3_flowrate;
		count++;
		holdIn( active, delay);
		return *this;
	}
	return *this;
		
		
}

/*** the internalFunction ***/
Model &ERP_mixing_7_model::internalFunction( const InternalMessage &msg )
{

			
	passivate();
	return *this;
		
		
}

/*** the outputFunction ***/
Model &ERP_mixing_7_model::outputFunction( const InternalMessage &msg )
{

			
	if(count == 3)
	{
		sendOutput( msg.time(), ERP_mixing_7_stream_DO_4, ERP_mixing_7_stream_DO_4_flowrate);
		ERP_mixing_7_stream_DO_4_flowrate = 0;
		count = 0;
	}
	return *this;
		
		
}

